package com.suray.wcs.service.view;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.suray.wcs.service.pojo.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * @Description
 * @author  guyue
 * @date    2020-05-22 16:04
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ComponentView {

    private String type;
    private String field;
    private String title;
    private Object value;
    private List<Map> options;
    private Map props;
    private Map col;
    private List<Map> validate;
    private Map event;

    public ComponentView() {
    }

    public ComponentView(Component component, String lang) {
        this.type = component.getType1();
        this.field = component.getField();
        this.title = "CN".equals(lang) ? component.getTitlecn() : "EN".equals(lang) ?
                component.getTitleen() : component.getTitlejp();
        this.value = component.getValue1();
        Map props = new HashMap();
        if (component.getPropstype() != null && !component.getPropstype().equals("")) {
            props.put("type", component.getPropstype());
        }
        if ("select".equals(component.getType1())) {
            String tmp = "CN".equals(lang) ? "无匹配数据" : "EN".equals(lang) ?
                    "No matching data" : "マッチングデータがありません";
            props.put("not-found-text", tmp);
            tmp = "CN".equals(lang) ? "请选择" : "EN".equals(lang) ?
                    "Please select" : "選択してください";
            props.put("placeholder", tmp);
        }
        if (component.getReadonly1() != 0) {
            props.put("readonly", true);
        }
        if (component.getDisabled1() != 0) {
            props.put("disabled", true);
        }
        this.props = props;
        List vatmp = new ArrayList();
        if (component.getRequired1() != 0) {
            Map map = new HashMap();
            map.put("required", component.getRequired1() == 1 ? true : false);
            map.put("message", component.getRequiredmesage());
            map.put("trigger", component.getTrigger1());
            vatmp.add(map);
        }
        this.validate = vatmp;
        if (component.getSpan() != 0) {
            Map map = new HashMap();
            map.put("span", component.getSpan());
            // map.put("labelWidth",150);
            this.col = map;
        }

        if (component.getEvent1() != null) {
            Map map = new HashMap();
            map.put(component.getEvent1(), "undefined");
            this.event = map;
        }
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Object getValue() {
        return value;
    }

    public Map getCol() {
        return col;
    }

    public void setCol(Map col) {
        this.col = col;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public List<Map> getOptions() {
        return options;
    }

    public void setOptions(List<Map> options) {
        this.options = options;
    }

    public Map getProps() {
        return props;
    }

    public void setProps(Map props) {
        this.props = props;
    }


    public List<Map> getValidate() {
        return validate;
    }

    public void setValidate(List<Map> validate) {
        this.validate = validate;
    }

    public Map getEvent() {
        return event;
    }

    public void setEvent(Map event) {
        this.event = event;
    }

    @Override
    public String toString() {
        return "ComponentView{" +
                "type='" + type + '\'' +
                ", field='" + field + '\'' +
                ", title='" + title + '\'' +
                ", value=" + value +
                ", options=" + options +
                ", props=" + props +
                ", col=" + col +
                ", validate=" + validate +
                ", event=" + event +
                '}';
    }
}
